<!doctype html>
<html class="no-js">
<head>
    <title>ZTE 中兴金融科技</title>
    {{include 'base/style.html'}}
    <link rel="stylesheet" href="{{=URL('static','module/login/css/app.css')}}">
</head>
<style>
</style>
<body data-type="login" style="background: #334054;">
<button id="close" type="button" class=" am-close am-close-spin">&times;</button>
<div class="am-g myapp-login" >
	<div class="myapp-login-bg">


            <div class="myapp-login-logo-text">
                验证码已经发送到{{=request.vars.username}}手机号中
            </div>
	            <form id="form" action="" class="am-form">
					<fieldset>
						<div class="am-form-group">
						<label for="code">验证码</label>
						<input type="text" id="code" minlength="4" maxlength="4" placeholder="请输入验证码" class="am-form-field" required/>
						</div>
                        <div class="am-form-group">
                        <label for="password">新密码</label>
                        <input type="password" id="password" minlength="1" placeholder="请输入密码" class="am-form-field"
                               required/>
                        </div>
						<div class="am-form-group myapp-login-treaty"><label class="am-form-label"></label><label class="am-checkbox-inline">收不到验证码请联系客服</label></div>
						<button class="myapp-login-button am-btn am-btn-secondary" type="button" id="finsh_btn">完成找回密码</button>
					</fieldset>

				</form>




	</div>
</div>


<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
  <div class="am-modal-dialog">
    <div class="am-modal-hd">验证码错误</div>
      <div class="am-modal-bd"></div>
    <div class="am-modal-footer">
      <span class="am-modal-btn">确定</span>
    </div>
  </div>
</div>

<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert-sc">
  <div class="am-modal-dialog">
    <div class="am-modal-hd">密码修改成功请登录,正在跳转</div>
      <div class="am-modal-bd"></div>

  </div>
</div>

{{include 'base/jsFile.html'}}
<script>
    var temp="{{=request.vars.type}}";
    var url= "{{=URL('finance','mind')}}";
    if(temp==1){
       url= "{{=URL('finance','myassets')}}";
    }
    $('#close').click(function () {
        window.location.href =url;
    })


    $('#finsh_btn').click(function () {
    var code= document.getElementById("code");
    if(code.value==""){
        code.setCustomValidity("验证码不能为空");
    }else{
        code.setCustomValidity("");
    }

    var password = document.getElementById("password");
    if(password.value==""){
         password.setCustomValidity("密码不能为空");
    }
    else{
        password.setCustomValidity("");
    }



        if(document.getElementById("form").checkValidity()){
            data_param={"username":'{{=request.vars.username}}',"code":code.value, "password":password.value}
            $.ajax({//http://10.204.127.36:8000/appweb/v1/test/1.json
                //url:"{{=URL('v1','test')}}/1.json",
                url:"{{=URL('v1','findpw')}}",
                type: "POST",
                data:JSON.stringify(data_param),
                headers:{
                    "cube_user_token":"123token",
                    "Content-Type":"application/json"
                },
                contentType: 'text/html; charset=UTF-8',
                dataType: "json",
                success: function(data) {
//                   alert(JSON.stringify(data)); // Object
                    if(data.errors!="code"){
//                        $('#my-alert').modal();
//                        alert(1)
                        if(data.updated=="1"){
                          $('#my-alert-sc').modal();
                          setTimeout(function(){
                             window.location.href ="{{=URL('finance','login')}}?type={{=request.vars.type}}"
                          },1000);
                        }else{
                            alert(data.errors);
                        }
                    }else{
                        $('#my-alert').modal();
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
        //            alert(XMLHttpRequest.status);
        //            alert(XMLHttpRequest.readyState);
                    alert(errorThrown);
                },
                complete: function(XMLHttpRequest, textStatus) {
                }

            });

        }



    })



</script>
</body>
</html>